//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pss;

import com.aidong.cache.NameItem;
import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.PssProductCodeDao;
import com.aidong.model.wills.PssForPopProduct;
import com.aidong.util.DateUtil;
import com.aidong.web.controller.member.PayController;
import java.util.Date;
import java.util.Iterator;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"popProduct"})
public class PopProductController extends PayController {
    @Resource
    PssProductCodeDao pssProductCodeDao;

    public PopProductController() {
    }

    @RequestMapping({"getProduct"})
    public ModelAndView getProduct(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "saleFlg",required = false) String saleFlg) {
        ModelAndView mv = new ModelAndView("pss/popproduct/list");
        mv.addObject("productTypeLst", this.getTypeList("productType"));
        mv.addObject("shopCode", shopCode);
        mv.addObject("saleFlg", saleFlg);
        return mv;
    }

    @RequestMapping({"_getProductList"})
    public ModelAndView _getProductList(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "saleFlg",required = false) String saleFlg, @RequestParam(value = "productName",required = false) String productName, @RequestParam(value = "spell",required = false) String spell, @RequestParam(value = "productType",required = false) String productType, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        ModelAndView mv = new ModelAndView("pss/popproduct/_list");
        if(!this.chkNull(shopCode)) {
            cd.eq("a.shopCode", shopCode);
            cd.like("b.productName", "%" + productName + "%");
            cd.like("b.spell", "%" + spell + "%");
            cd.eq("b.productType", productType);
            if(!this.chkNull(saleFlg) && "1".equals(saleFlg)) {
                Date i$ = new Date();
                String prod = DateUtil.formatDate(i$, "yyyy-MM-dd") + " 00:00:00";
                cd.le("b.GroundingDate", this.parseDate(prod, "yyyy-MM-dd HH:mm:ss"));
                cd.ge("b.UndercarriageDate", this.parseDate(prod, "yyyy-MM-dd HH:mm:ss"));
                cd.eq("b.SaleFlg", "1");
                mv.addObject("saleFlg", saleFlg);
            }

            this.pssProductCodeDao.getProductStockLst(pg, cd);
            mv.addObject("shopCode", shopCode);
        } else {
            cd.like("b.productName", "%" + productName + "%");
            cd.like("b.spell", "%" + spell + "%");
            cd.eq("b.productType", productType);
            this.pssProductCodeDao.queryProductPageList(pg, cd);
        }

        if(pg.getResultList() != null) {
            Iterator i$1 = pg.getResultList().iterator();

            while(i$1.hasNext()) {
                PssForPopProduct prod1 = (PssForPopProduct)i$1.next();
                NameItem item = this.cache.getNameItem("productType", prod1.getProductType());
                if(item != null) {
                    prod1.setUseGiftCard(this.parseInt(item.getProp()));
                }
            }
        }

        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }
}
